<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
request.setCharacterEncoding("UTF-8");
%>

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<!DOCTYPE html>
<html>
<head>
<!-- Coded By CoinBin -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-3.2.1.js"></script>
<script type="text/javascript">
	function delUser(id){
		if(window.confirm("是否删除该用户？")){
				window.location.href="${pageContext.request.contextPath }/user/delete/"+id;
		}
	}
	function selEml(email){
		window.location.href="${pageContext.request.contextPath }/user/selectEml/"+email;
	}
</script>
<meta charset="UTF-8">
<title>用户查询</title>
</head>
<style>
	th{text-align: center;}
</style>
<body>
	<div style="padding: 20px 0px 10px 140px;">
		<form:form modelAttribute="user" method="post"
			action="${pageContext.request.contextPath }/user/selectEml" class="form-inline">
			<label>查询Email</label>
			<form:input path="bemail" class="form-control" placeholder="Email"/>
			<input type="submit" value="查询" class="btn btn-primary"/>
			${selectMsg }
			
		</form:form>
	</div>
	<div align="center">
		<div style="width: 100%; text-align: center;font-weight: bold;font-size: 20px; padding: 10px;">用户列表</div>
		<table class="table table-hover" style="width: 80%;">
	
			<tr>
				<th>#</th>
				<th>用户邮箱</th>
				<th>操作</th>
			</tr>
	
			<c:forEach items="${userList }" var="user">
				<tr>
					<th>${user.id}</th>
					<th>${user.bemail}</th>
					<th><input type="button" value="删除"
						onclick="delUser(${user.id})" class="btn btn-danger"></th>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="3">
				<c:if test="${pageNumber<=7}">
						<c:forEach var="i" begin="1" end="${pageNumber}">
							<c:if test="${page == i }">
								<a href="${pageContext.request.contextPath }/user/select/${i}"
									target="center" style="pointer-events: none;" class="btn btn-primary">${i }</a>
								
							</c:if><c:if test="${page != i }">
							<a href="${pageContext.request.contextPath }/user/select/${i}"
								target="center" class="btn btn-default">${i }</a>
							</c:if>
						</c:forEach>
					</c:if>
				
				<c:if test="${page <=4&&pageNumber>7}">
						<c:forEach var="i" begin="1" end="${page+2}">
							<c:if test="${page == i }">
								<a href="${pageContext.request.contextPath }/user/select/${i}"
									target="center" style="pointer-events: none;" class="btn btn-primary">${i }</a>
								
							</c:if><c:if test="${page != i }">
							<a href="${pageContext.request.contextPath }/user/select/${i}"
								target="center" class="btn btn-default">${i }</a>
							</c:if>
						</c:forEach>
						…
						<a href="${pageContext.request.contextPath }/user/select/${pageNumber}"
								target="center" class="btn btn-default">${pageNumber }</a>
					</c:if>
					
					<c:if test="${page >4&&pageNumber>7&&page<pageNumber-3}">
					<a href="${pageContext.request.contextPath }/user/select/1"
								target="center" class="btn btn-default">1</a>…
						<c:forEach begin="${page-2}" end="${page+2 }" var="i">
							<c:if test="${page == i }">
								<a href="${pageContext.request.contextPath }/user/select/${i}"
									target="center" style="pointer-events: none;" class="btn btn-primary">${i }</a>
								
							</c:if><c:if test="${page != i }">
							<a href="${pageContext.request.contextPath }/user/select/${i}"
								target="center" class="btn btn-default">${i }</a>
							</c:if>
						</c:forEach>
						…
						<a href="${pageContext.request.contextPath }/user/select/${pageNumber}"
								target="center" class="btn btn-default">${pageNumber }</a>
					</c:if>
					
					<c:if test="${pageNumber>7&&page>=pageNumber-3}">
					<a href="${pageContext.request.contextPath }/user/select/1"
								target="center" class="btn btn-default">1</a>…
						<c:forEach begin="${page-2}" end="${pageNumber}" var="i">
							<c:if test="${page == i }">
								<a href="${pageContext.request.contextPath }/user/select/${i}"
									target="center" style="pointer-events: none;" class="btn btn-primary">${i }</a>
								
							</c:if><c:if test="${page != i }">
							<a href="${pageContext.request.contextPath }/user/select/${i}"
								target="center" class="btn btn-default">${i }</a>
							</c:if>
						</c:forEach>
						
					</c:if>
					
					</td>
			</tr>
		</table>
	</div>

</body>
</html>